 <html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人信息</title>
    <link href="css/swiper-5.4.5/swiper.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/my.css" rel="stylesheet">
    <link href="./css/font-awesome.css" rel="stylesheet">
    <link href="./css/element/index.css" rel="stylesheet">
    <style>
        .nx-nav-container ul{
            width: 100%;
            height: 100%;
            margin: 0 auto;
            display: flex;
            justify-content: center;
        }
        .nx-nav-container ul li{
            display: inline-block;
            width: 120px;
            text-align: center;
            line-height: 45px;
        }
        .nx-nav-container a{
            color: #FFFFFF;
        }
        .nx-nav-container a:hover {
            color: aquamarine;
            text-decoration: none;
        }
        td{
            vertical-align: middle !important;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <div class="nx-header">
        <div style="display: flex;width: 100%;height: 30px;line-height: 30px;background-color: #eee;">
            <div style="flex: 5;padding: 0 10px; color: orangered;">
                欢迎访问 电影订票购票系统
            </div>
            <div v-if="user.name" style="flex: 1">
                欢迎您： {{user.name}}
                <a style="margin-left: 30px;color: blue;" href="javascript:void(0);" @click="logout">退出</a>
            </div>
        </div>
    </div>

    <div style="height: 80px; line-height: 80px;">
        <div style="margin-left: 20px;position: relative;">
            <img src="img/logo1.png" style="width: 40px;position: absolute;top: 20px;">
            <b style="margin-left: 45px;font-size:25px;text-shadow: 5px 5px 3px #888888">电影订票购票系统</b>
        </div>
    </div>

    <div class="nx-nav-container" style="height: 45px;background-color: black;">
        <ul>
            <li><a href="index.html">首页</a></li>
            <li><a href="advertiserInfo.html">公告信息</a></li>
            <li><a href="messageInfo.html">在线交流信息</a></li>
            <li><a href="linkInfo.html">友情链接</a></li>
            <li><a href="cartInfo.html">收藏栏信息</a></li>
            <li><a href="orderInfo.html">订单信息</a></li>
            <li><a href="commonInfo.html">评价信息</a></li>
            <li class="active"><a href="javascript:void(0)" @click="personalPage">个人信息</a></li>
            <li v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a></li>
            <li v-if="!isLogin"><a href="/end/page/login.html" target="_blank">登录</a></li>
            <li v-if="!isLogin"><a href="/end/page/register.html" target="_blank">注册</a></li>
        </ul>
    </div>

    <div class="container" style="margin-top: 20px;">
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        个人信息
                    </div>
                    <input type="hidden" v-model="entity.id">
                    <div class="panel-body">
                        <form class="form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">姓名</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" v-model="entity.name" placeholder="请输入姓名" id="name">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">昵称</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" v-model="entity.nickName" placeholder="请输入昵称" id="nickName">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">性别</label>
                                <div class="col-sm-7">
                                    <label class="radio-inline">
                                        <input type="radio" value="男" v-model="entity.sex">男
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" value="女" v-model="entity.sex">女
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">年龄</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" v-model="entity.age" placeholder="请输入年龄" id="age">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">生日</label>
                                <div class="col-sm-7">
                                    <el-data-picker v-model="entity.birthday" id="birthday" type="datetime" clearable value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间" ></el-data-picker>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">手机号</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" v-model="entity.phone" placeholder="请输入手机号" id="phone">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">地址</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" v-model="entity.address" placeholder="请输入地址" id="address">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">邮政编码</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" v-model="entity.code" placeholder="请输入邮政编码" id="code">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">电子邮箱</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" v-model="entity.email" placeholder="请输入电子邮箱" id="email">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">身份证</label>
                                <div class="col-sm-7">
                                    <input type="text" class="form-control" v-model="entity.cardId" placeholder="请输入身份证" id="cardId">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">账户余额</label>
                                <div class="col-sm-7" style="line-height: 35px">
                                    ￥{{entity.account}}
                                </div>
                            </div>
                            <div style="text-align: center">
                                <button type="button" class="btn btn-primary" v-on:click="account=100" date-toggle="modal" data-target="#rechargeModal">充值</button>
                                <button type="button" class="btn btn-primary" v-on:click="update()">保存</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>

    <!--充值模态框-->
<div class="modal" id="rechargeModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <span class="modal-title">充值</span>
                <button type="button" class="close" data-dismiss="modal" @click="entity={}">&times;</button>
            </div>
            <div class="modal-body">
                <div class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">金额</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" v-model="account" placeholder="请输入充值金额"></input>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" @click="recharge()">确定</button>
            </div>
        </div>
    </div>
</div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="../end/js/jquery.metisMenu.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/my.js"></script>
<script src="js/element/index.js"></script>
<script>
    new Vue({
        el: "#wrapper",
        data: {
            user: {}, // 当前登录用户
            isShow: false, // 是否显示进入后台
            isLogin: false, //是否已经登陆
            entity: {
                sex: '男'
            },
            account:null
        },
        created: function () {
           this.loadData();
        },
        methods: {
            loadData(){
                // 查询权限
                axios.get('/auth').then(res =>{
                    if(res.data.code == '0'){
                        this.user = res.data.data;
                        if(this.user.level === 1){
                            this.isShow = true;
                        }
                        this.isLogin = true;
                        axios.get("/getAccountInfo").then(res => {
                            if (res.data.code === '0') {
                                this.entity = res.data.data;
                            } else {
                                alert(res.data.msg);
                            }
                        });
                    }else{
                        alert('请先登录');
                        location.href = '/end/page/login.html';
                    }
                });
            },
            //保存个人信息
            update(){
                axios.put("/userInfo",this.entity).then(res => {
                    if (res.data.code === '0') {
                        alert("更新成功");
                        this.loadData();
                    } else {
                        alert(res.data.msg);
                    }
                });
            },
            //充值
            recharge(){
                let data = {id:this.entity.id,account: parseFloat(this.entity.account) + parseFloat(this.account)};
                axios.put("/userInfo",data).then(res => {
                    if (res.data.code === '0') {
                        alert("充值成功");
                        $("#rechargeModal").modal('hide');
                        this.loadData();
                    } else {
                        alert(res.data.msg);
                    }
                });
            },

            logout(){
                axios.get('/logout').then(res =>{
                    if(res.data.code === '0'){
                        location.href = '/front/index.html';
                    }else{
                        alert(res.data.msg);
                    }
                });
            },
        }
    });
</script>
</body>
</html>